{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<div class="think-box-shadow">

    <table class="layui-table margin-top-10" lay-filter="mxTable" lay-skin="line" id="mxTable">
    </table>
    <script type="text/html" id="toolbarDemo">
        <a href="javascript:" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="dels">删除</a>
    </script>
</div>
{/block}
{block name="script"}
<!-- /主体 -->
<script>
    const moduleInit = ['tool'];
    function gouguInit() {
        var form =layui.form;
        let statusArr=['','草稿','已确认','已撤回'];
        var treeTable = layui.table;
        // $.extend(treeTable, {config: {checkName: 'checked'}});
        var tableIns = treeTable.render({
            elem: '#mxTable'
            , url: "{:url('')}?receiptId={$receiptId}"
            , method: 'post'
            ,toolbar: '#toolbarDemo'
            ,defaultToolbar: []
            , cellMinWidth: 80
            , cols: [[
                {type: 'checkbox', fixed: 'left'},
                {fixed: 'left', field: 'id', title: 'ID', unresize: true, hide: true}
                // ,{field: 'id', width: 80, title: 'ID号', align: 'center'}
                , {field: 'dName', title: '销售单位'}
                , {field: 'contractOrder', title: '合同号'}
                , {field: 'money', title: '到款金额'}
                , {field: 'create_time', title: '到款时间'}
                // , {field: 'status', title: '状态',templet:function (d) {
                //     return statusArr[d.status];
                //     }}
                , {title: '操作', align: 'center'
                    , templet: function (d) {
                        var html = '' +
                            '<button class="layui-btn layui-btn-danger  layui-btn-xs" lay-event="edit">编辑</button>' +
                            '';
                        return html;
                    }
                }
            ]]
            , page: true
        });

        treeTable.on('toolbar(mxTable)', function (obj) {
            var checkStatus = treeTable.checkStatus(obj.config.id);
            console.log(checkStatus)
            switch (obj.event) {
                case 'add':
                    break;
                case 'dels':
                    var data = checkStatus.data;
                    console.log('dddd',data)
                    let ids=[];
                    data.forEach(function (value, index) {
                       ids.push(value.id)
                    })
                    if (ids.length<1){
                        layer.msg('请选择数据');
                        return;
                    }
                    let param={ids:ids};
                    httpRequest("{:url('delDkMx')}?receiptId={$receiptId}",param,function (res) {
                        if (res.code==0){
                            setTimeout(function () {
                                parent.parent.location.reload();
                            },1000)

                        }
                    })

                    break;
                case 'import':

                    break;

            }
            ;
        })
        treeTable.on('tool(mxTable)', function (obj) {
            console.log(obj);

            if (obj.event === 'edit') {
                layer.open({
                    type: 1,
                    title: '修改金额',
                    area: ['500px', '200px'],
                    btn: ['确定'],
                    content: '<form class="layui-form" id="printForm" action="">' +
                        '  <div class="layui-form-item" >' +
                        '    <label class="layui-form-label" style="margin: 0;width: 90px">金额</label>' +
                        '    <div class="layui-input-block">' +
                        '      <input type="text " style="width: 200px" class="layui-input" id="monye" value="'+obj.data.money+'"   name="monye" onkeyup="digitalFiltering(this,2)" title="金额">' +
                        '    </div>' +
                        '  </div>' +
                        '</form>',
                    success: function (layero, index) {
                        // 渲染表单

                        form.render();
                        //
                        // // 监听提交事件
                        // form.on('radio(printType)', function(data){
                        //     console.log(data.value); // 获取选中的值
                        //     layer.close(index); // 关闭弹窗
                        // });
                    },
                    yes: function (index) {
                        let mon = $("#monye").val()
                        let param={
                            id:obj.data.id,
                            money:mon
                        };
                        httpRequest("{:url('htdkEdit')}",param,function (res) {
                            if (res.code==0){
                                layer.close(index);
                            } else {
                                layer.msg(res.msg)
                            }
                        },false)

                    }
                });
                return;
            }
        });
    }

    function saveMx(data) {
        parent.saveAddMx(data)

    }
</script>
<!-- 脚本 -->
{/block}


